﻿using MediatR;
using Tb.App.API.Applications.Command.Basic;
using Tb.App.Domain.Rabbit.Basic;
using Tb.App.ErrorCode;
using Tb.App.Infrastructure.Interfaces;

namespace Tb.App.API.Applications.CommandHandler.Basic
{
    /// <summary>
    /// 商品信息查询(绑定)
    /// </summary>
    public class GetStoreCommandHandler : IRequestHandler<GetStoreCommand, ApiResult<List<StoreModel>>>
    {
        private readonly IBaseRepository<StoreModel> storeRep;

        public GetStoreCommandHandler(IBaseRepository<StoreModel> storeRep)
        {
            this.storeRep = storeRep;
        }
        public Task<ApiResult<List<StoreModel>>> Handle(GetStoreCommand request, CancellationToken cancellationToken)
        {

            ApiResult<List<StoreModel>> result=new ApiResult<List<StoreModel>>();
            result.Code=ApiEnum.查询成功;
            result.Message=ApiEnum.查询成功.ToString();
            var list = storeRep.GetAll().Where(x => !x.IsDel).ToList();
            result.Data= list;

            return Task.FromResult(result);
            
        }
    }
}
